package com.hxzy.service.Impl;

import com.hxzy.bean.Message;
import com.hxzy.dao.Impl.MessageDaoImpl;
import com.hxzy.dao.MessageDao;
import com.hxzy.service.MessageService;
import com.hxzy.util.CommonUtil;
import com.hxzy.vo.MessageVo;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

public class MessageServiceImpl implements MessageService {
    private MessageDao dao=new MessageDaoImpl();
    @Override
    public int save(Message message) {
        return dao.save(message);
    }

    @Override
    public int update(Message message) {
        return dao.update(message);
    }

    @Override
    public int remove(Integer integer) {
        return dao.remove(integer);
    }

    @Override
    public List<Message> queryAll() {
        return dao.queryAll();
    }

    @Override
    public Message findById(Integer integer) {
        return dao.findById(integer);
    }

    @Override
    public List<MessageVo> queryAllMessageVo() {
        List<Message> messages = this.queryAll();
        return messages.stream().map(t ->{
            MessageVo messageVo=new MessageVo();
            messageVo.setId(t.getId());
            messageVo.setTopic(t.getTopic());
            messageVo.setContent(t.getContent());
            LocalDateTime mesDate = t.getMesDate();
            String string = CommonUtil.timeToString(mesDate);
            messageVo.setMesDate(string);
            messageVo.setNickName(t.getUser().getNickName());
            return messageVo;
        }).collect(Collectors.toList());
    }
}
